<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>gozerlib.plugs.misc &mdash; GOZERWAVE v0.1 BETA documentation</title>
    <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '0.1 BETA',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <link rel="top" title="GOZERWAVE v0.1 BETA documentation" href="../../index.html" />
    <link rel="next" title="gozerlib.plugs.more" href="more.html" />
    <link rel="prev" title="gozerlib.plugs.login" href="login.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../modindex.html" title="Global Module Index"
             accesskey="M">modules</a> |</li>
        <li class="right" >
          <a href="more.html" title="gozerlib.plugs.more"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="login.html" title="gozerlib.plugs.login"
             accesskey="P">previous</a> |</li>
        <li><a href="../../index.html">GOZERWAVE v0.1 BETA documentation</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="module-gozerlib.plugs.misc">
<h1>gozerlib.plugs.misc<a class="headerlink" href="#module-gozerlib.plugs.misc" title="Permalink to this headline">¶</a></h1>
<p>misc commands.</p>
<dl class="function">
<dt id="gozerlib.plugs.misc.get_time">
<tt class="descclassname">gozerlib.plugs.misc.</tt><tt class="descname">get_time</tt><big>(</big><em>zone</em>, <em>username</em>, <em>authuser</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.misc.get_time" title="Permalink to this definition">¶</a></dt>
<dd>get the time of a user.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.misc.handle_ask_timezone">
<tt class="descclassname">gozerlib.plugs.misc.</tt><tt class="descname">handle_ask_timezone</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.misc.handle_ask_timezone" title="Permalink to this definition">¶</a></dt>
<dd>ask for a users timezone.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.misc.handle_source">
<tt class="descclassname">gozerlib.plugs.misc.</tt><tt class="descname">handle_source</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.misc.handle_source" title="Permalink to this definition">¶</a></dt>
<dd>source .. show where to fetch the bot source.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.misc.handle_test">
<tt class="descclassname">gozerlib.plugs.misc.</tt><tt class="descname">handle_test</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.misc.handle_test" title="Permalink to this definition">¶</a></dt>
<dd>test .. give test response which is a string of the ircevent.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.misc.handle_time">
<tt class="descclassname">gozerlib.plugs.misc.</tt><tt class="descname">handle_time</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.misc.handle_time" title="Permalink to this definition">¶</a></dt>
<dd>show current time</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.misc.handle_timezone">
<tt class="descclassname">gozerlib.plugs.misc.</tt><tt class="descname">handle_timezone</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.misc.handle_timezone" title="Permalink to this definition">¶</a></dt>
<dd>timezone .. set current timezone.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.misc.set_timezone">
<tt class="descclassname">gozerlib.plugs.misc.</tt><tt class="descname">set_timezone</tt><big>(</big><em>bot</em>, <em>ievent</em>, <em>userstate</em>, <em>timezone</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.misc.set_timezone" title="Permalink to this definition">¶</a></dt>
<dd>set a users timezone.</dd></dl>

<div class="section" id="code">
<h2>code<a class="headerlink" href="#code" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python"><table class="highlighttable"><tr><td class="linenos"><pre>  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130</pre></td><td class="code"><div class="highlight"><pre><span class="c"># plugs/misc.py</span>
<span class="c">#</span>
<span class="c">#</span>

<span class="sd">&quot;&quot;&quot; misc commands. &quot;&quot;&quot;</span>

<span class="c">## gozerbot imports</span>

<span class="kn">from</span> <span class="nn">gozerlib.commands</span> <span class="kn">import</span> <span class="n">cmnds</span>
<span class="kn">from</span> <span class="nn">gozerlib.examples</span> <span class="kn">import</span> <span class="n">examples</span>
<span class="kn">from</span> <span class="nn">gozerlib.aliases</span> <span class="kn">import</span> <span class="n">aliasset</span>
<span class="kn">from</span> <span class="nn">gozerlib.persist.persiststate</span> <span class="kn">import</span> <span class="n">UserState</span>

<span class="c">## basic imports</span>

<span class="kn">import</span> <span class="nn">time</span><span class="o">,</span> <span class="nn">os</span><span class="o">,</span> <span class="nn">threading</span><span class="o">,</span> <span class="nn">thread</span>

<span class="k">def</span> <span class="nf">handle_test</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; test .. give test response which is a string of the ircevent. &quot;&quot;&quot;</span>

    <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;</span><span class="si">%s</span><span class="s"> .. it works!&quot;</span> <span class="o">%</span> <span class="n">ievent</span><span class="o">.</span><span class="n">userhost</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;test&#39;</span><span class="p">,</span> <span class="n">handle_test</span><span class="p">,</span> <span class="p">[</span><span class="s">&#39;USER&#39;</span><span class="p">,</span> <span class="s">&#39;WEB&#39;</span><span class="p">,</span> <span class="s">&#39;JCOLL&#39;</span><span class="p">,</span> <span class="s">&#39;CLOUD&#39;</span><span class="p">,</span> <span class="p">],</span> <span class="n">options</span><span class="o">=</span><span class="p">{</span><span class="s">&#39;--t&#39;</span><span class="p">:</span> <span class="s">&#39;bla&#39;</span><span class="p">})</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;test&#39;</span><span class="p">,</span> <span class="s">&#39;give test response&#39;</span><span class="p">,</span><span class="s">&#39; test&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;test&#39;)</span>

<span class="k">def</span> <span class="nf">handle_source</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; source .. show where to fetch the bot source. &quot;&quot;&quot;</span> 

    <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;see http://gozerwave.googlecode.com&#39;</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;source&#39;</span><span class="p">,</span> <span class="n">handle_source</span><span class="p">,</span> <span class="p">[</span><span class="s">&#39;USER&#39;</span><span class="p">,</span> <span class="s">&#39;WEB&#39;</span><span class="p">,</span> <span class="s">&#39;CLOUD&#39;</span><span class="p">])</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;source&#39;</span><span class="p">,</span> <span class="s">&#39;show source url&#39;</span><span class="p">,</span> <span class="s">&#39;source&#39;</span><span class="p">)</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;about&#39;</span><span class="p">,</span> <span class="s">&#39;source&#39;</span><span class="p">)</span>

<span class="c">#tests.add(&#39;source&#39;, &#39;gozerbot&#39;)</span>

<span class="k">def</span> <span class="nf">handle_time</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; show current time &quot;&quot;&quot;</span>

    <span class="n">authuser</span> <span class="o">=</span> <span class="n">username</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">userhost</span>

    <span class="k">if</span> <span class="n">authuser</span><span class="p">:</span>
        <span class="n">userstate</span> <span class="o">=</span> <span class="n">UserState</span><span class="p">(</span><span class="n">username</span><span class="p">)</span>

        <span class="k">try</span><span class="p">:</span>
            <span class="n">tz</span> <span class="o">=</span> <span class="n">userstate</span><span class="p">[</span><span class="s">&#39;TZ&#39;</span><span class="p">]</span>
        <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
            <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;</span><span class="si">%s</span><span class="s"> doesn&#39;t have a timezone set .. use !set TZ &quot;</span> <span class="o">%</span> <span class="n">username</span><span class="p">)</span>
            <span class="k">return</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="n">get_time</span><span class="p">(</span><span class="n">tz</span><span class="p">,</span> <span class="n">username</span><span class="p">,</span> <span class="n">authuser</span><span class="p">))</span>

    <span class="k">else</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="n">get_time</span><span class="p">(</span><span class="s">&#39;UTC&#39;</span><span class="p">,</span> <span class="s">&#39;&#39;</span><span class="p">,</span> <span class="s">&#39;&#39;</span><span class="p">))</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;time&#39;</span><span class="p">,</span> <span class="n">handle_time</span><span class="p">,</span> <span class="p">[</span><span class="s">&#39;USER&#39;</span><span class="p">,</span> <span class="s">&#39;CLOUD&#39;</span><span class="p">],</span> <span class="n">threaded</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;time&#39;</span><span class="p">,</span> <span class="s">&#39;show current time (of a user)&#39;</span><span class="p">,</span> <span class="s">&#39;time test&#39;</span><span class="p">)</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;t&#39;</span><span class="p">,</span> <span class="s">&#39;time&#39;</span><span class="p">)</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;date&#39;</span><span class="p">,</span> <span class="s">&#39;time&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;time&#39;)</span>

<span class="k">def</span> <span class="nf">handle_timezone</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; timezone .. set current timezone. &quot;&quot;&quot;</span>

    <span class="n">username</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">userhost</span>

    <span class="k">if</span> <span class="ow">not</span> <span class="n">ievent</span><span class="o">.</span><span class="n">rest</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">missing</span><span class="p">(</span><span class="s">&#39;&lt;timezone&gt; (integer)&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="k">if</span> <span class="n">username</span><span class="p">:</span>
        <span class="n">userstate</span> <span class="o">=</span> <span class="n">UserState</span><span class="p">(</span><span class="n">username</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">ievent</span><span class="o">.</span><span class="n">rest</span><span class="p">:</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">timezone</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">ievent</span><span class="o">.</span><span class="n">rest</span><span class="p">)</span>
                
                <span class="n">set_timezone</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">,</span> <span class="n">userstate</span><span class="p">,</span> <span class="n">timezone</span><span class="p">)</span>
            <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
                <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;TZ needs to be an integer&#39;</span><span class="p">)</span>
                <span class="k">return</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;can&#39;t determine timezone&quot;</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;timezone&#39;</span><span class="p">,</span> <span class="n">handle_timezone</span><span class="p">,</span> <span class="p">[</span><span class="s">&#39;USER&#39;</span><span class="p">],</span> <span class="n">threaded</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;timezone&#39;</span><span class="p">,</span> <span class="s">&#39;set current timezone&#39;</span><span class="p">,</span> <span class="s">&#39;timezone +1&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;timezone&#39;)</span>

<span class="k">def</span> <span class="nf">handle_ask_timezone</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; ask for a users timezone. &quot;&quot;&quot;</span>

    <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;what is your timezone ? for example -1 or +4&#39;</span><span class="p">)</span>
    <span class="n">response</span> <span class="o">=</span> <span class="n">waitforuser</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="o">.</span><span class="n">userhost</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">response</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">response</span><span class="o">.</span><span class="n">txt</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;can&#39;t determine timezone .. not setting it&quot;</span><span class="p">)</span>
        <span class="k">return</span>

<span class="k">def</span> <span class="nf">set_timezone</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">,</span> <span class="n">userstate</span><span class="p">,</span> <span class="n">timezone</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; set a users timezone. &quot;&quot;&quot;</span>

    <span class="c"># check for timezone validity and return False, if necessary</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="n">tz</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">timezone</span><span class="p">)</span>
    <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;timezone needs to be an integer&#39;</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">False</span>

    <span class="n">userstate</span><span class="p">[</span><span class="s">&#39;TZ&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">tz</span>
    <span class="n">userstate</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
    <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;timezone set to </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">tz</span><span class="p">)</span>
    <span class="k">return</span> <span class="bp">True</span>

<span class="k">def</span> <span class="nf">get_time</span><span class="p">(</span><span class="n">zone</span><span class="p">,</span> <span class="n">username</span><span class="p">,</span> <span class="n">authuser</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; get the time of a user. &quot;&quot;&quot;</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">zone</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">zone</span><span class="p">)</span>
    <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
        <span class="n">zone</span> <span class="o">=</span> <span class="mf">0</span>

    <span class="k">return</span> <span class="n">time</span><span class="o">.</span><span class="n">ctime</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o">+</span> <span class="nb">int</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">timezone</span><span class="p">)</span> <span class="o">+</span> <span class="n">zone</span><span class="o">*</span><span class="mf">3600</span><span class="p">)</span>
</pre></div>
</td></tr></table></div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h3><a href="../../index.html">Table Of Contents</a></h3>
            <ul>
<li><a class="reference external" href="">gozerlib.plugs.misc</a><ul>
<li><a class="reference external" href="#code">code</a></li>
</ul>
</li>
</ul>

            <h4>Previous topic</h4>
            <p class="topless"><a href="login.html"
                                  title="previous chapter">gozerlib.plugs.login</a></p>
            <h4>Next topic</h4>
            <p class="topless"><a href="more.html"
                                  title="next chapter">gozerlib.plugs.more</a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="../../_sources/gozerlib/plugs/misc.txt"
                     rel="nofollow">Show Source</a></li>
            </ul>
          <div id="searchbox" style="display: none">
            <h3>Quick search</h3>
              <form class="search" action="../../search.html" method="get">
                <input type="text" name="q" size="18" />
                <input type="submit" value="Go" />
                <input type="hidden" name="check_keywords" value="yes" />
                <input type="hidden" name="area" value="default" />
              </form>
              <p class="searchtip" style="font-size: 90%">
              Enter search terms or a module, class or function name.
              </p>
          </div>
          <script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../modindex.html" title="Global Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="more.html" title="gozerlib.plugs.more"
             >next</a> |</li>
        <li class="right" >
          <a href="login.html" title="gozerlib.plugs.login"
             >previous</a> |</li>
        <li><a href="../../index.html">GOZERWAVE v0.1 BETA documentation</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; Copyright 2009, Bart Thate.
      Last updated on Nov 14, 2009.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.3.
    </div>
  </body>
</html>